﻿namespace My.Hydrator.Conventions
{
    using System;
    using System.ComponentModel.Composition;

    [Export(typeof(ITypeConvention))]
    public class BooleanTypeConvention : BaseTypeConvention, ITypeConvention
    {
        public Type Type
        {
            get { return typeof(bool); }
        }

        public object GenerateValue(object[] customAttributes)
        {
            this.GetAttributes(customAttributes);

            if (this.IsDataTypeAttributePresent)
            {
                var formatter = this.GetFormatter(this.DataTypeAttribute);
                if (formatter != null)
                {
                    return formatter.GetFormat();
                }
            }

            return this.Random.NextDouble() > 0.5;
        }
    }
}
